﻿/************************************************************************

 This file is part of EscapeFromPrisonPlanet.

 EscapeFromPrisonPlanet is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 EscapeFromPrisonPlanet is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

************************************************************************/

// All code (c)2012 Scott Bevin. all rights reserved

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace LudumDare25Project.GameScreens
{
    internal class HelpScreen : GameScreen
    {
        private List<Texture2D> helpSlides = new List<Texture2D>();
        private int currentSlide = 0;

        private WhiteFadeScreen fadeScreen = null;

        public HelpScreen()
            : base(true)
        {
        }

        public override void OnAdded()
        {
            bool done = false;
            int counter = 0;

            while (!done)
            {
                try
                {
                    Texture2D tex = ContentManager.Load<Texture2D>("Img/Help/Help" + counter.ToString());
                    helpSlides.Add(tex);
                    counter++;
                }
                catch (Exception e)
                {
                    done = true;
                }
            }

            base.OnAdded();
        }

        public override void Update(float dt, InputManager input)
        {
            if (fadeScreen == null)
            {
                if (input.MouseButtonStates[(int)InputManager.MouseButtons.LeftButton].Released ||
                    input.MouseButtonStates[(int)InputManager.MouseButtons.RightButton].Released)
                {
                    fadeScreen = new WhiteFadeScreen();
                    GameScreenManager.AddGameScreen(fadeScreen, null, LudumDare25Project.GameScreenManager.AddGameScreenData.PositioningOptions.OnTop);
                }
            }
            else
            {
                if (fadeScreen.State == WhiteFadeScreen.States.FadedIn)
                {
                    ++currentSlide;
                    fadeScreen.FadeOut();

                    if (currentSlide >= helpSlides.Count)
                    {
                        GameScreenManager.AddGameScreen(new MainMenuScreen(), fadeScreen, LudumDare25Project.GameScreenManager.AddGameScreenData.PositioningOptions.BelowRef);
                        this.KillScreen = true;
                    }
                }

                if (fadeScreen.KillScreen)
                    fadeScreen = null;
            }

            base.Update(dt, input);
        }

        public override void Render(float dt, Microsoft.Xna.Framework.Graphics.GraphicsDevice gd, Microsoft.Xna.Framework.Graphics.SpriteBatch sprites)
        {
            sprites.Begin();

            sprites.Draw(
                helpSlides[currentSlide],
                new Rectangle(0, 0, gd.PresentationParameters.BackBufferWidth, gd.PresentationParameters.BackBufferHeight),
                Color.White);

            sprites.End();

            base.Render(dt, gd, sprites);
        }
    }
}